package com.android.fragmentdemo
import android.os.Bundle
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.android.fragmentdemo.adapters.DynamicItem01Adapter
import com.android.fragmentdemo.adapters.DynamicItem02Adapter
import com.android.fragmentdemo.adapters.DynamicItem03Adapter
import com.hengfoxwolf.commonbase.base.BaseActivity3
import com.android.fragmentdemo.databeans.DataFactoryIp
import com.android.fragmentdemo.databinding.ActivityNestedScrollViewBinding
import com.android.fragmentdemo.defineviews.Dy0101ItemDecoration
import com.android.fragmentdemo.defineviews.GridItemDecoration
import com.android.fragmentdemo.defineviews.List01DataItemDecoration

class NestedScrollViewActivity :
    BaseActivity3<ActivityNestedScrollViewBinding>(ActivityNestedScrollViewBinding::inflate) {

    override fun init(savedInstanceState: Bundle?) {

        val headerAdapter = DynamicItem01Adapter()
        headerAdapter.itemDataSet = DataFactoryIp.createCharStr(10)
        mBinding.rvHead.apply {
            layoutManager = LinearLayoutManager(
                this@NestedScrollViewActivity,
                LinearLayoutManager.HORIZONTAL,
                false
            )
            adapter = headerAdapter
            addItemDecoration(
                Dy0101ItemDecoration(
                    resources.getDimension(
                        R.dimen.dp_10
                    )
                ).apply {
                    setFirstItemSpace(true)
                }
            )
        }

        val bodyAdapter = DynamicItem02Adapter()
        bodyAdapter.itemDataSet = DataFactoryIp.createColorList()
        mBinding.rvBody.apply {
            layoutManager = GridLayoutManager(
                this@NestedScrollViewActivity,
                4
            )
            adapter = bodyAdapter
            addItemDecoration(GridItemDecoration(this@NestedScrollViewActivity, 4))
        }

        val centerAdapter = DynamicItem03Adapter()
        centerAdapter.itemDataSet = DataFactoryIp.createStrDataSet().subList(0,12)
        mBinding.rvCenter.apply {
            layoutManager = LinearLayoutManager(
                this@NestedScrollViewActivity,
            )
            adapter = centerAdapter
            addItemDecoration(
                List01DataItemDecoration(
                    this@NestedScrollViewActivity,
                    this@NestedScrollViewActivity.resources.getDimension(R.dimen.dp_10)
                ).apply {
                    setDrawLastLine(false)
                })
        }

        val footerAdapter = DynamicItem02Adapter()
        footerAdapter.itemDataSet = DataFactoryIp.createColorList().subList(0, 10)
        mBinding.rvFooter.apply {
            layoutManager = GridLayoutManager(
                this@NestedScrollViewActivity,
                3
            )
            adapter = footerAdapter
            addItemDecoration(GridItemDecoration(this@NestedScrollViewActivity, 3))
        }


        //滚动到底部
        //val child = mBinding.nestedScrollView[mBinding.nestedScrollView.childCount - 1]
        //mBinding.nestedScrollView.scrollTo(0, child.bottom)

        //滚动到顶部
        //mBinding.nestedScrollView.scrollTo(0, child.top)
        //mBinding.nestedScrollView.scrollTo(0, 0)
    }

}